﻿using System.Data;
using DataHelper;
namespace DAL
{
  public  class FileDao
    {

      public DataTable GetOneInfo(string nFileID)
      {
          string strSecSQL = "SELECT * FROM File_List WHERE FileID=" + nFileID;
          return SQLHelper.ExecuteSqlGetDataSet(strSecSQL).Tables[0];
      }
      public bool InsertOneInfo(string desn,string url,string isDir,string parentID,string account ,string companyID,string departmentID,string propertie,string statu,string extName,string fileLen,string memo)
      {
          ///添加新数据
          string strInsertSQL = "INSERT INTO File_List (Desn,Url,IsDir,ParentID,Account,CompanyID,DepartmentID,Propertie,Statu,extName,fileLen,Memo) ";
          strInsertSQL += " values ('" + desn + "','" + url + "'," + isDir + "," + parentID + ",'" + account + "'," + companyID + "," + departmentID + ",'" + propertie + "','" + statu + "','"+extName+"',"+fileLen+",'"+memo+"')";
          return SQLHelper.ExecuteSql(strInsertSQL);
      }
      public bool UpdateOneInfo(string desn, string nFileID)
      {
          string strUpdateSQL = "UPDATE File_List SET Desn='" + desn + "' WHERE FileID=" + nFileID;
          return SQLHelper.ExecuteSql(strUpdateSQL);
      }
      public bool DeleteOneInfo(string nFileID)
      {
          DataTable dt = GetOneInfo(nFileID);          

          System.IO.FileInfo Fi = new System.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath(dt.Rows[0]["Url"].ToString()));
          if (Fi.Exists)
          {
              Fi.Delete();
          }
          string strSecSQL = "delete FROM File_List WHERE FileID=" + nFileID;
          return SQLHelper.ExecuteSql(strSecSQL);
      }
      public DataTable GetLists()
      {
          string sql = "SELECT * FROM File_List ORDER BY AbsIndex ASC ";
          return SQLHelper.ExecuteSqlGetDrToDt(sql);
      }
      public DataTable GetLists(string fileID)
      {
          string sql = "SELECT * FROM File_List where ParentID=" + fileID + " and IsDir<>1 ORDER BY AbsIndex ASC";
          return SQLHelper.ExecuteSqlGetDrToDt(sql);
      }
      public DataTable GetDtlLists(string fileID)
      {
          string sql = "SELECT * FROM File_ListDtl where FileID=" + fileID + "   ORDER BY DtlID ASC";
          return SQLHelper.ExecuteSqlGetDrToDt(sql);
      }
    }
}
